package com.smommo.myapp.Processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;

@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    //Bean工厂后置处理器，当BeanFactory准备好了后(Bean初始化，之前)，会调用该接口的
    //postProcessBeanFactory方法，经常用于新增BeanDefinition
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        GenericBeanDefinition gbdf=new GenericBeanDefinition();
        gbdf.setBeanClass(Teacher.class);
        //向下强转
        DefaultListableBeanFactory factory = (DefaultListableBeanFactory) beanFactory;
        factory.registerBeanDefinition("teacher",gbdf);
    }
}
